package com.zaofan.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.zaofan.bean.SmsLog;
import com.zaofan.dao.base.DaoSupportImpl;

public class SmsLogDao extends DaoSupportImpl<SmsLog> {

	public List<SmsLog> findTodayLogs(String mobile) {
		try {
			String sql = "select * from " + SmsLog.class.getSimpleName().toLowerCase()
					+ " where date(sendTime) = curdate() and mobile = '" + mobile + "'";
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new BeanListHandler<>(SmsLog.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public Long CountTodayLogs(String mobile) {
		try {
			String sql = "select count(*) from " + SmsLog.class.getSimpleName().toLowerCase()
					+ " where date(sendTime) = curdate() and mobile = '" + mobile + "'";
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new ScalarHandler<Long>());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
